<?php
/****************************************************************************

	COPYRIGHT(C) WWW.MAXSI.DK, MAXSI SOFTWARE, SORTIE 2009
	ALL RIGHTS RESERVED

	Maxsi Distribution Shared/ Branch
	Scripts shared by the MasterServer/ and ContentServer/ Branch of the Maxsi
	Distribution Server-Side Code Branches.
		
	quote.php
	Functions for making sure slashes are correct.
	
****************************************************************************/

function	md_SlashGlobalVar($in)
{
	if (!get_magic_quotes_gpc())
	{
		return addslashes($in);
	}
	else
	{
		return	$in;
	}
}

function md_RequestParam($name)
{
	if (isset($_GET[$name]))
	{
		return	$_GET[$name];
	}
	if (isset($_POST[$name]))
	{
		return	$_POST[$name];
	}
	if (isset($_COOKIE[$name]))
	{
		return	$_COOKIE[$name];
	}
	return;
}

function md_RequestParamSlashed($name)
{
	return md_RequestParam(md_SlashGlobalVar($name));
}

// HTML2TEXT, replaces < and > with &lt; and &gt;
function md_html2text($htmlinput, $abortfunction = 0)
{
	if ($abortfunction==1) return $htmlinput;
	return str_replace("<","&lt;",str_replace(">","&gt;",str_replace("\"","&quot;",str_replace("&","&amp;",$htmlinput))));
}

// TEXT2HTNL, replaces &lt; and &gt with < and >;
function md_text2html($htmlinput, $abortfunction = 0)
{
	if ($abortfunction==1) return $htmlinput;
	return str_replace("&lt;","<",str_replace("&gt;",">",str_replace("&quot;","\"",$htmlinput)));
}

function md_ProductNameToFileName($ProductName)
{
	return str_replace("+"," ",str_replace("%20"," ",rawurlencode($ProductName)));
}

function md_ContentArchiveNameToContentArchiveId($ProductName)
{
	global $md_sql_row;
	
	$product_slot	=	md_sql("SELECT id FROM ".md_GetDatabaseName('contentarchive')." WHERE name='".$ProductName."'");
	
	$result			=	$md_sql_row[$product_slot]['id'];
	
	md_clearslot($product_slot);
	
	return $result;	
}

function md_FileNameToProductName($FileName)
{
	return urldecode(str_replace(" ","%20",$FileName));
}

function md_FileNameToHTTPURL($FileName)
{
	return rawurlencode($FileName);
}

function md_HTTPURLToFileName($HTTPURL)
{
	return rawurldecode($HTTPURL);
}

function md_IsValidProductName($ProductName)
{
	// Products may have all ASCII characters in their names,
	// except they may not be called 'addons' for security reasons.
	
	if (	strcasecmp($ProductName,"") == 0 ||
			strcasecmp($ProductName,"addons") == 0 )
	{
		return false;
	} 
	
	return true;
}

?>